-
Notifications
You must be signed in to change notification settings - Fork 36
Refactor Read_Grid_HDF5 to make use of FieldInfo
#468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
| // this should work whether Cholla is configured with COOLING_GRACKLE or CHEMISTRY_GPU | ||
| // - earlier versions of this logic wouldn't work with Grackle | ||
| static void cosmo_init_chemical_species_(const Header &H, const FieldInfo &field_info, Real *host_field_ptr) | ||
| { | ||
| if (!field_info.field_id("HI_density").has_value()) { | ||
| CHOLLA_ERROR("This function has been erroneously executed. There are no chemical species"); | ||
| } | ||
|
|
||
| Real *density = &host_field_ptr[H.n_cells * field_info.field_id("density").value()]; | ||
| Real *HI_density = &host_field_ptr[H.n_cells * field_info.field_id("HI_density").value()]; | ||
| Real *HII_density = &host_field_ptr[H.n_cells * field_info.field_id("HII_density").value()]; | ||
| Real *HeI_density = &host_field_ptr[H.n_cells * field_info.field_id("HeI_density").value()]; | ||
| Real *HeII_density = &host_field_ptr[H.n_cells * field_info.field_id("HeII_density").value()]; | ||
| Real *HeIII_density = &host_field_ptr[H.n_cells * field_info.field_id("HeIII_density").value()]; | ||
| Real *e_density = &host_field_ptr[H.n_cells * field_info.field_id("e_density").value()]; | ||
|
|
||
| for (int k = 0; k < H.nz_real; k++) { | ||
| for (int j = 0; j < H.ny_real; j++) { | ||
| for (int i = 0; i < H.nx_real; i++) { | ||
| int id = (i + H.n_ghost) + (j + H.n_ghost) * H.nx + (k + H.n_ghost) * H.nx * H.ny; | ||
| int buf_id = k + j * (H.nz_real) + i * (H.nz_real) * (H.ny_real); | ||
| HI_density[id] = INITIAL_FRACTION_HI * density[id]; | ||
| HII_density[id] = INITIAL_FRACTION_HII * density[id]; | ||
| HeI_density[id] = INITIAL_FRACTION_HEI * density[id]; | ||
| HeII_density[id] = INITIAL_FRACTION_HEII * density[id]; | ||
| HeIII_density[id] = INITIAL_FRACTION_HEIII * density[id]; | ||
| e_density[id] = INITIAL_FRACTION_ELECTRON * density[id]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following snippet is more consistent with the original style of the code that we replaced. I'm happy to revert it if that's your preference. But, be aware, I'm 99% that the old version is incompatible with Grackle.
For context, the defined(COOLING_GRACKLE) condition has been inserted for historical consistency, but I'm pretty sure the code won't compile -- Grid3D::Conserved doesn't have data members named HI_density, HII_density, ... in that mode
// this should work whether Cholla is configured with COOLING_GRACKLE or CHEMISTRY_GPU
// - earlier versions of this logic wouldn't work with Grackle
static void cosmo_init_chemical_species_(const Header &H, Grid3D::Conserved& C)
{
#if defined(COOLING_GRACKLE) || defined(CHEMISTRY_GPU)
for (int k = 0; k < H.nz_real; k++) {
for (int j = 0; j < H.ny_real; j++) {
for (int i = 0; i < H.nx_real; i++) {
int id = (i + H.n_ghost) + (j + H.n_ghost) * H.nx + (k + H.n_ghost) * H.nx * H.ny;
int buf_id = k + j * (H.nz_real) + i * (H.nz_real) * (H.ny_real);
C.HI_density[id] = INITIAL_FRACTION_HI * C.density[id];
C.HII_density[id] = INITIAL_FRACTION_HII * C.density[id];
C.HeI_density[id] = INITIAL_FRACTION_HEI * C.density[id];
C.HeII_density[id] = INITIAL_FRACTION_HEII * C.density[id];
C.HeIII_density[id] = INITIAL_FRACTION_HEIII * C.density[id];
C.e_density[id] = INITIAL_FRACTION_ELECTRON * C.density[id];
}
}
}
#endif
}4606463 to
0cb5308
Compare
This PR is a followup to #467
Quite simply, this PR refactors
Read_Grid_HDF5to make use of the newly introducedFieldInfotype.